var fs = require('fs');
var xml = require('xml2js');

exports.loadParseDocument = function(filename, callback){
    var parser = new xml.Parser();

    parser.addListener('end', callback);
    fs.readFile(process.cwd() + '/data/' + filename, function(err, data) {
        parser.parseString(data);
    });
}

exports.parseSaveObject = function(object, filename, callback) {
    var builder = new xml.Builder();
    var xmlString = builder.buildObject(object);
    fs.writeFile(process.cwd() + '/data/' + filename, xmlString, function (err) {
        if (err){
            console.log(err);
        } else {
            callback.call();
        }
    });
}